
/**
 * @file print.c
 *
 * Functions needed by print traversal.
 *
 */

/**
 * @defgroup print Print Functions.
 *
 * Functions needed by print traversal.
 *
 * @{
 */


#include "foo.h"
#include "traverse.h"
#include "tree_basic.h"
#include "dbug.h"
#include "memory.h"
#include "globals.h"


/*
 * INFO structure
 */
struct INFO {
  bool firsterror;
};

#define INFO_FIRSTERROR(n) ((n)->firsterror)

static info *MakeInfo()
{
  info *result;
  
  result = MEMmalloc(sizeof(info));

  INFO_FIRSTERROR(result) = FALSE;
  
  return result;
}


static info *FreeInfo( info *info)
{
  info = MEMfree( info);

  return info;
}

node *
FOObinop (node * arg_node, info * arg_info)
{
  DBUG_ENTER ("FOObinop");

  switch (BINOP_OP( arg_node)) {
    case BO_add:
      BINOP_OP( arg_node) = BO_sub;
      break;
    case BO_sub:
      BINOP_OP( arg_node) = BO_add;
      break;
    case BO_mul:
      BINOP_OP( arg_node) = BO_div;
      break;
    case BO_div:
      BINOP_OP( arg_node) = BO_mul;
      break;
    case BO_unknown:
      DBUG_ASSERT( 0, "unknown binop detected!");
  }
  arg_node = TRAVcont(arg_node, arg_info);
  DBUG_RETURN (arg_node);
}


/** <!-- ****************************************************************** -->
 * @brief Prints the given syntaxtree
 *
 * @param syntaxtree a node structure
 *
 * @return the unchanged nodestructure
 ******************************************************************************/

node
*FOOdoFoo( node *syntaxtree)
{
  info *info;

  DBUG_ENTER("FOOdoFoo");

  DBUG_ASSERT( (syntaxtree!= NULL), "FOOdoFoo called with empty syntaxtree");

  info = MakeInfo();

  TRAVpush( TR_foo);

  syntaxtree = TRAVdo( syntaxtree, info);

  TRAVpop();

  info = FreeInfo(info);

  DBUG_RETURN( syntaxtree);
}

/**
 * @}
 */
